package com.gtn.exam.title.persistence.connection.base.hibernate;

import java.io.File;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.gtn.exam.title.core.util.Constants;
import com.gtn.exam.title.persistence.connection.base.BaseFactory;
import com.gtn.exam.title.persistence.domain.Persistent;
import com.gtn.exam.title.persistence.domain.SystemLogin;
import com.gtn.exam.title.persistence.domain.TempTable;


/**
 * The factory Class which implements {@link BaseFactory}
 * 
 * @author Rukshan Silva | 13th August 2014
 * @version 1.0.0
 */
public class HibernateBaseFactory implements BaseFactory {
	
	private static SessionFactory sessionFactory= null;
	
	public HibernateBaseFactory() {

		sessionFactory = new AnnotationConfiguration().
				addAnnotatedClass(TempTable.class).
				addAnnotatedClass(Persistent.class).
				addAnnotatedClass(SystemLogin.class).
				configure(new File(Constants.resources.HIBERNATE_CONFIG_FILE)).
					buildSessionFactory();
	}
	
	/**
	 * {@inheritDoc}
	 */
	public void initConnection() {
		
//		sessionFactory = new AnnotationConfiguration().
//				configure(new File(Constants.resources.HIBERNATE_CONFIG_FILE)).
//					buildSessionFactory();
	}
	
	/**
	 * {@inheritDoc}
	 */
	public Session beginTransaction() {
		
		return sessionFactory.openSession();
	}
}